home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / BANDOG.ARJ / CERBERUS.ASM next >
Assembly Source File  |  1991-01-05  |  9KB  |  186 lines

  1.         TITLE   CERBERUS
  2.  
  3. ; In Greek myths, on guard before the gate to the underworld sits Cerberus, the
  4. ; three-headed, dragon-tailed dog, who permits all spirits to enter, but none
  5. ; to return.
  6. ;
  7. ; CERBERUS.ASM prompts the user to enter a password.  The user is allowed three
  8. ; tries to get the password correct.  If the user does not enter the correct
  9. ; password after three tries, the system performs a warm boot.  The user cannot
  10. ; break out using either Control-C or Control-Break.  Periods are echoed for
  11. ; the password input.
  12.  
  13. _TEXT   SEGMENT
  14.         ASSUME  CS:_TEXT,DS:_TEXT,SS:_TEXT
  15.         ORG     100h
  16.  
  17. BEGIN:
  18.         MOV     CX,3                    ; Load number of tries into CX
  19.  
  20.         LEA     SI,MESSAGE1             ; Print system message
  21.         CALL    WRITELN
  22.  
  23. PASSWD_LOOP:
  24.         LEA     SI,PROMPT               ; Print the prompt
  25.         CALL    WRITELN
  26.  
  27.         LEA     DI,BUFFER               ; Get string input into BUFFER
  28.         CALL    GETSTR
  29.  
  30.         XOR     AL,AL                   ; Set return code to 0
  31.         LEA     SI,PASSWORD             ; Compare password and buffer
  32.         CALL    STRCMP
  33.         JC      FINISH                  ; Return to DOS if strings are equal
  34.  
  35.         LEA     SI,MESSAGE2             ; Inform user of incorrect input
  36.         CALL    WRITELN
  37.  
  38.         LOOP    PASSWD_LOOP             ; Loop until out of tries
  39.  
  40.         LEA     SI,MESSAGE3             ; Print reboot message
  41.         CALL    WRITELN
  42.  
  43.         DB      0EAh,00h,00h,0FFh,0FFh  ; JMP FFFF:0000
  44. FINISH:
  45.         MOV     AH,4Ch                  ; Exit to DOS
  46.         INT     21h
  47.  
  48. ;-----------------------------------------------------------------------;
  49. ; This procedure outputs a string.                                      ;
  50. ;                                                                       ;
  51. ; Uses:                                                                 ;
  52. ;       SI              Address of string                               ;
  53. ;                                                                       ;
  54. ; Returns:                                                              ;
  55. ;       Nothing                                                         ;
  56. ;-----------------------------------------------------------------------;
  57. WRITELN:
  58.         PUSH    AX                      ; Save AX
  59.         PUSH    SI                      ; Save SI
  60.  
  61. WRITELN_LOOP:
  62.         MOV     AL,[SI]                 ; Display character at SI
  63.         CMP     AL,0                    ; Have we reached the null terminator?
  64.         JE      EXIT_WRITELN            ; Yes, return to calling function
  65.         INT     29h                     ; Call fast putchar function
  66.         INC     SI                      ; Increment pointer
  67.         JMP     WRITELN_LOOP            ; Repeat for remaining characters
  68.  
  69. EXIT_WRITELN:
  70.         POP     SI                      ; Restore SI
  71.         POP     AX                      ; Restore AX
  72.         RET
  73.  
  74. ;-----------------------------------------------------------------------;
  75. ; This procedure reads in a string from the standard input device.      ;
  76. ; Extended keys, backspaces, and carriage returns are the only keys     ;
  77. ; processed.  All other input is stored in a buffer.                    ;
  78. ;                                                                       ;
  79. ; Uses:                                                                 ;
  80. ;       DI              Address of string                               ;
  81. ;       GET_CHAR        Reads a character from the standard input       ;
  82. ;                                                                       ;
  83. ; Returns:                                                              ;
  84. ;       Nothing                                                         ;
  85. ;-----------------------------------------------------------------------;
  86. GETSTR:
  87.         PUSH    AX                      ; Save AX
  88.         PUSH    SI                      ; Save SI
  89.         PUSH    DI                      ; Save DI
  90.  
  91. GETSTR_LOOP:
  92.         CALL    GET_CHAR                ; Get a character
  93.         CMP     AL,0                    ; Is the character a null?
  94.         JNE     IS_CTRL_C               ; No, check for Control-C
  95.         CALL    GET_CHAR                ; Get scan code for extended key
  96.         JMP     GETSTR_LOOP             ; Loop again
  97. IS_CTRL_C:
  98.         CMP     AL,3                    ; Is the character a Control-C?
  99.         JNE     IS_BS                   ; No, check for backspace
  100.         JMP     GETSTR_LOOP             ; Loop again
  101. IS_BS:
  102.         CMP     AL,8                    ; Is the character a backspace?
  103.         JNE     IS_CR                   ; No, check for carriage return
  104.         CMP     DI,OFFSET BUFFER        ; Are we at beginning of input buffer?
  105.         JE      GETSTR_LOOP             ; Yes, do not erase last character
  106.         LEA     SI,BACKSPACE            ; No, erase last character entered
  107.         CALL    WRITELN
  108.         DEC     DI                      ; Decrement pointer
  109.         JMP     GETSTR_LOOP             ; Loop again
  110. IS_CR:
  111.         CMP     AL,13                   ; Is the character a carriage return?
  112.         JE      EXIT_GETSTR             ; Yes, return to calling function
  113.         MOV     [DI],AL                 ; Add character to buffer
  114.         INC     DI                      ; Increment pointer
  115.         MOV     AL,'.'                  ; Print period using fastchar function
  116.         INT     29h
  117.         JMP     GETSTR_LOOP             ; Loop again
  118.  
  119. EXIT_GETSTR:
  120.         MOV     BYTE PTR [DI],0         ; Terminate string with a null
  121.         POP     DI                      ; Restore DI
  122.         POP     SI                      ; Restore SI
  123.         POP     AX                      ; Restore AX
  124.         RET
  125.  
  126. ;-----------------------------------------------------------------------;
  127. ; This procedure reads a character from the standard input device       ;
  128. ; without echo.                                                         ;
  129. ;                                                                       ;
  130. ; Uses:                                                                 ;
  131. ;       Nothing                                                         ;
  132. ;                                                                       ;
  133. ; Returns:                                                              ;
  134. ;       AL              Character read                                  ;
  135. ;-----------------------------------------------------------------------;
  136. GET_CHAR:
  137.         MOV     AH,07h                  ; Read character from standard input
  138.         INT     21h
  139.         RET
  140.  
  141. ;-----------------------------------------------------------------------;
  142. ; This procedure compares two null-terminated strings.                  ;
  143. ;                                                                       ;
  144. ; Uses:                                                                 ;
  145. ;       SI              Source string                                   ;
  146. ;       DI              Comparision string                              ;
  147. ;                                                                       ;
  148. ; Returns:                                                              ;
  149. ;       CF              Set if strings are equal                        ;
  150. ;-----------------------------------------------------------------------;
  151. STRCMP:
  152.         PUSH    AX                      ; Save AX
  153.         PUSH    SI                      ; Save SI
  154.         PUSH    DI                      ; Save DI
  155.  
  156. STRCMP_LOOP:
  157.         MOV     AL,[SI]                 ; Make a copy of the source character
  158.         CMP     AL,[DI]                 ; Are the two characters equal?
  159.         JE      ARE_EQUAL               ; Yes, continue comparisons
  160.         CLC                             ; No, clear carry flag (return value)
  161.         JMP     EXIT_STRCMP             ; Return to calling function
  162. ARE_EQUAL:
  163.         INC     SI                      ; Increment data pointers
  164.         INC     DI
  165.         CMP     AL,0                    ; Is source character a null?
  166.         JNE     STRCMP_LOOP             ; No, loop again
  167.         STC                             ; Yes, set carry flag (strings equal)
  168.  
  169. EXIT_STRCMP:
  170.         POP     DI                      ; Restore DI
  171.         POP     SI                      ; Restore SI
  172.         POP     AX                      ; Restore AX
  173.         RET
  174.  
  175. MESSAGE1        DB      7,'System password protected.',13,10,0
  176. MESSAGE2        DB      7,13,10,'Password incorrect.',13,10,0
  177. MESSAGE3        DB      13,10,'System rebooting...',0
  178. PROMPT          DB      13,10,'Password: ',0
  179. PASSWORD        DB      'oki794',0
  180. BUFFER          DB      8 DUP('BUFFER    ')
  181. BACKSPACE       DB      8,' ',8,0
  182.  
  183. _TEXT   ENDS
  184.  
  185.         END     BEGIN
  186.